home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / misc / worldmap / world / mpstomp1.c < prev    next >
Text File  |  1985-12-28  |  2KB  |  86 lines

  1. /*  Copyright (C) 1985 John B. Allison                December 1985
  2.  
  3.   mpstomp1 -    convert mps binary format files to mp1 ASCII format.
  4.                                     */
  5. main(argc, argv)
  6.   int  argc;
  7.   char *argv[];{
  8.  
  9. #include "stdio.h"
  10.  
  11. FILE *fp;
  12.  
  13. #define RECSIZE 90
  14.  
  15. #define READMODE    0x8000
  16. #define WRITEMODE    0x8001
  17.  
  18.     int      n, ix, blank, fi;
  19.     char  ss[80], fullname[80], c, zchar = 26;    /*  Ctrl Z - EOF  */
  20.     float xvalue,  yvalue;
  21.     double x, y;
  22.     char   outname[80];
  23.  
  24.  
  25.  
  26.  
  27.     if(argc != 3 || argv[2][1] != ':' || argv[2][2] != '\0'){
  28.         printf("        useage: mpstomp1 file_name disk_drive\n");
  29.         printf("\nwhere 'file_name' is a file name (excluding drive designation and extension). \n");
  30.         printf("This program will create an mp1-formated\n");
  31.         printf("file named 'x:file_name.mps'\n");
  32.         exit();
  33.     }
  34.  
  35.     /*  Input File  */
  36.  
  37.     strcpy(fullname, argv[1]);
  38.     strcat(fullname, ".mps");
  39.  
  40.     if((fi=open(fullname, READMODE)) == -1){
  41.         printf("Unable to open %s\n", fullname);
  42.         exit();
  43.     }
  44.  
  45.     /*  Output File  */
  46.  
  47.     strcpy(outname, argv[2]);
  48.     strcat(outname, argv[1]);
  49.     strcat(outname, ".mp1");
  50.  
  51.     if((fp=fopen(outname, "r")) != NULL){
  52.         printf("Output file %s already exists.\n", outname);
  53.         exit();
  54.     }
  55.     if((fp=fopen(outname, "w")) == NULL){
  56.         printf("Unable to create %s\n", outname);
  57.         exit();
  58.     }
  59.  
  60.  
  61.  
  62.     /*  Read and process the binary map file.  */
  63.  
  64.     while(read(fi, &xvalue, 4) != 0){
  65.         if(read(fi, &yvalue, 4) == -1) goto error;
  66.         x = xvalue;
  67.         y = yvalue;
  68.         fprintf(fp, "%.3f %.3f", x, y);
  69.  
  70.         for(read(fi, &c, 1); c != '\n'; read(fi, &c, 1)){
  71.             if(c == 1){
  72.                 fprintf(fp, "\n");
  73.                 continue;
  74.             }
  75.             fprintf(fp, "%c", c);
  76.         }
  77.  
  78.         fprintf(fp, "\n");
  79.     }
  80.  
  81.     fprintf(fp, "%c", zchar);    /*  End of File  -  Ctrl Z  */
  82.     exit();
  83.  
  84. error:
  85.     printf("Read error on file %s\n", fullname);
  86. }